<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>试卷接口测试</title>
	<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
	<script src="bootstrap/js/jQuery-2.1.4.min.js"></script>
	<script src="bootstrap/js/bootstrap.min.js"></script>
</head>

<body>
	<div class="container">
		<div class="row clearfix">
			<div class="col-md-12 column" style="margin-top: 15px;">
				选择word文件<input class="wordfile" type="file">
			</div>
			<div class="col-md-12 column" style="margin-top: 150px;">
				<div class="tabbable" id="tabs-929339">
					<ul class="nav nav-tabs">
						<li class="active">
							<a href="#panel-292035" data-toggle="tab">上传word文件</a>
						</li>
						<li>
							<a href="#panel-115725" data-toggle="tab">导出pdf</a>
						</li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="panel-292035">
							<div class="col-md-12 column" style="margin-top: 15px;">
								<button class="btn btn-ms btn-primary" type="button" onclick="toWord()">转json</button>
								<div class="resp-res" style="width:100%" ></div>
							</div>
						</div>
						<div class="tab-pane" id="panel-115725">
							<button class="btn btn-ms btn-primary" type="button" onclick="toPdf()">转pdf</button>
							<div class="resp-res2" style="width:100%" ></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
	var path = 'upload';
	$('.wordfile').on("change",function(e){
		//upload()
	});
	function toWord(){
		path = 'upload';
        $('.resp-res').html('文件上传中');
		upload()
	}
	function toPdf(){
		var title = prompt("请输入pdf文档标题", "hello");
		if(title){
			path = 'expert';
	        $('.resp-res2').html('生成中...');
			upload(title)
		}
	}
    function upload(title){
    	var fileDom = $('.wordfile'), formData = new FormData();
    	if(!fileDom.val()){
			alert('请先选择文件');
			return false;
		}
    	formData.append("file", fileDom[0].files[0]);
    	formData.append("title", title?title:'');
    	 $.ajax({
             url: path,
             type: "POST",
             data: formData,
             processData:false,
             contentType:false,
             success: function (resp) {
				 if(path == 'upload'){
					 $('.resp-res').html(JSON.stringify(resp));
				 }else{
					 if(resp.indexOf('http') >= 0){
						 $('.resp-res2').html('<a href="'+resp+'" target="_blank">点击查看pdf</a>');
					 }else{
						 $('.resp-res2').html(resp);
					 }
				 }
             },
             error: function (err) {
            	$('.resp-res').html('文件上传异常');
             }
         })
    }
	</script>
</body>

</html>